<template>
    <div>
        <div style="margin-top: 16px;" v-if="state.dataList.length != 0">
            <Table :columns="allSchemas.tableColumns" @refresh="refresh" :headerCellStyle="headerCellStyle"
                :rowStyle="rowStyle" :data="state.dataList" @register="tableRegister" />
            <!-- <Table v-if="!state.refush" :columns="allSchemas.tableColumns" :headerCellStyle="headerCellStyle" :rowStyle="rowStyle"
                :data="state.dataList" @register="tableRegister" /> -->
        </div>
        <el-empty description="暂无数据" v-if="state.dataList.length == 0" />
        <div class="flex jcc aic List_content_footer" style="margin-top: 16px;">
            <el-pagination :current-page="state.ruleForm.pageNum" :page-size="state.ruleForm.pageSize"
                layout="total,sizes, prev, pager, next" :total="state.total" @size-change="handleSizeChange"
                @current-change="handleCurrentChange" :page-sizes="[10, 20, 50, 100,500]" />
        </div>
    </div>
</template>

<script setup lang="tsx">
import { Table } from '@/components/Table'
import { positionRegistrationList, findAddressList } from "@/api/home/index"
import { ElButton, ElInput, ElMessage, ElMessageBox, ElSwitch, ElLoading } from 'element-plus'
import { dictFuns } from "@/utils/dictUnit"
import { useTable } from '@/hooks/web/useTable'
import { ref, reactive, watch, nextTick } from 'vue'
import { useRouter } from 'vue-router'
// import service from './service'
import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
import config from '@/config/axios/config'
import { useStorage } from '@/hooks/web/useStorage'
import { useAppStoreWithOut } from '@/store/modules/app'
const { defaultHeaders } = config
const { getStorage } = useStorage()
const appStore = useAppStoreWithOut()

const { push } = useRouter()
const emit = defineEmits(['listVue'])
const props = defineProps({
    positionId: {
        type: String,
        default: () => {
            return ""
        }
    },
})
// 表格头部信息
const headerCellStyle: any = {
    "background": "#F2F6FC",
    "height": "48px"
}
// 
const rowStyle: any = {
    "height": "48px"
}
// 处理状态数据
const statusFun = (item) => {
    let string = ""
    if (props.type == 0 || props.type == 1) {
        if (!item.initialScreeningUnqualifiedLabel) {
            string = "合格【系统】"
        } else {
            arrayFun(item.initialScreeningUnqualifiedLabel).forEach(element => {
                if (string) {
                    string = string + ";" + element
                } else {
                    string = element
                }
            });
        }
    } else if (props.type == 2) {
        if (item.writingTestingStatus == 2) {
            string = "已接受笔试"
        } else if (item.writingTestingStatus == 1) {
            string = "已通知笔试"
        } else if (item.writingTestingStatus == 0) {
            string = "未通知笔试"
        } else if (item.writingTestingResult == 1) {
            string = "笔试通过"
        } else if (item.writingTestingResult == 0) {
            string = "笔试未通过"
        }
    } else if (props.type == 3) {
        string = "面试"
    } else if (props.type == 4) {
        if (item.status == 5) {
            string = "背景调查"
        } else if (item.status == 6) {
            string = "体检审查"
        } else if (item.status == 7) {
            string = "录用通知/公示"
        }
    } else if (props.type == 5) {
        string = "入职"
    }
    return string
}
const state = reactive({
    dataList: [] as any,
    list: [] as any,
    total: 0,
    statusData:[
        {id:"1",label:"初筛"},
        {id:"-1",label:"初筛未通过"},
        {id:"2",label:"应聘部门筛选"},
        {id:"-2",label:"应聘部门筛选未通过"},
        {id:"3",label:"笔试"},
        {id:"-3",label:"笔试未通过"}, 
        {id:"4",label:"面试"},
        {id:"-4",label:"面试未通过"}, 
        {id:"5",label:"背景调查"},
        {id:"-5",label:"背景调查未通过"}, 
        {id:"6",label:"体检"},
        {id:"-6",label:"体检未通过"}, 
        {id:"7",label:"录用"},
        {id:"-7",label:"录用未通过"}, 
        {id:"8",label:"待入职"},
        {id:"-8",label:"待入职未通过"}, 
        {id:"9",label:"入职"},
        {id:"-9",label:"入职完成"}, 
    ],
    ruleForm: {
        currentAddress: "",//地址
        statusNotIn: 0,
        statusIn: "-9,-8,-7,-6,-5,-4,-3,-2,-1,1,2,3,4,5,6,7,8,9",
        // statusGe: "",
        // statusLe: "",
        searchValue: "",
        positionId: props.positionId,
        educationLevel: "",//学历
        requirementsYears: "",//工作经验
        arrivalTime: "",//到岗时间
        isAsc: "asc",
        pageNum: 1,
        pageSize: 10,
        deptId: "",//部门
        orderByColumn: "",
        gender: "",//性别
        jobSearchStatus: "",//求职状态
        lookingForwardSalary: "",//期望薪资
        createTimeStart: "",//投递开始时间
        createTimeEnd: "",//投递结束时间
        initialScreeningUnqualifiedLabel: "",//简历标签
        lookingForwardIndustry: "",//期望从事行业
        writingTestingTimeStart: "",//笔试开始时间
        writingTestingTimeEnd: "",//笔试结束时间
        writingTestingResult: "",//笔试结果
        writingTestingStatus: "",//笔试状态
        interviewDateStart: "",//面试开始时间
        interviewDateEnd: "",//面试结束时间
        medicalReportStatus: "",//体检报告
        schoolName: "",//学校名称
        xuexinCoding: "",//学信网编码
        companyName: "",//公司名称
        positionName: "",//职位名称
        workDescription: "",//工作描述
        selfEvaluation: "",//自我评价
        onBoardTimeStart: "",//入职时间
        onBoardTimeEnd: "",//入职结束
        isRead: "",//已读未读

    } as any,
})
const { tableMethods, tableRegister } = useTable({
    fetchDataApi: async () => {
        return {}
    }
})
const { getElTableExpose, setColumn, refresh } = tableMethods
// 表格基本信息
const crudSchemas = reactive<CrudSchema[]>([
    // {
    //     field: 'selection',
    //     type: 'selection'
    // },
    {
        field: 'field',
        label: '姓名',
        fixed: "left",
        hidden: false,
        table: {
            slots: {
                default: (data: any) => {
                    return (
                        <>
                            <div>{data[0].row.resumeVo?.personalInformation?.fullName}</div>
                        </>
                    )
                }
            }
        }
    },
    {
        field: 'initialScreeningUnqualifiedLabel',
        label: '简历标签',
        // hidden: true,
        table: {
            slots: {
                default: (data: any) => {
                    return (
                        <>
                            <div>{dictFuns(data[0].row.initialScreeningUnqualifiedLabel, "resume_label") || "无"}</div>
                        </>
                    )
                }
            }
        }
    },
    {
        field: 'field',
        label: '性别',
        hidden: true,
        table: {
            slots: {
                default: (data: any) => {
                    return (
                        <>
                            <div>{dictFuns(data[0].row.resumeVo.personalInformation.gender, "sys_user_sex") || "无"}</div>
                        </>
                    )
                }
            }
        }
    },
    {
        field: 'field',
        label: '年龄',
        table: {
            slots: {
                default: (data: any) => {
                    return (
                        <>
                            <div>{data[0].row.resumeVo?.personalInformation?.age}</div>
                        </>
                    )
                }
            }
        }
    },
    {
        field: 'field',
        label: '工作年限',
        table: {
            slots: {
                default: (data: any) => {
                    return (
                        <>
                            <div>{startWorkTimeFun(data[0].row.resumeVo.personalInformation?.startWorkTime) || "无"}</div>
                        </>
                    )
                }
            }
        }
    },
    {
        field: 'field',
        label: '期望薪资',
        // hidden: true,
        table: {
            slots: {
                default: (data: any) => {
                    return (
                        <>
                            <div>{dictFuns(data[0].row.resumeVo.personalInformation?.lookingForwardSalary, "salary") || "无"}</div>
                        </>
                    )
                }
            }
        }
    },
    {
        field: 'sms_typeName',
        label: '最高学历',
        table: {
            slots: {
                default: (data: any) => {
                    return (
                        <>
                            <div>{dictFuns(data[0].row.resumeVo.educationExperiences.length != 0 ? data[0].row.resumeVo.educationExperiences[data[0].row.resumeVo.educationExperiences.length -
                                1].educationLevel : null, "education") || "无"}</div>
                        </>
                    )
                }
            }
        }
    },
    {
        field: 'sms_typeName',
        label: '学校',
        table: {
            slots: {
                default: (data: any) => {
                    return (
                        <>
                            <div>{data[0].row.resumeVo.educationExperiences.length != 0 ? data[0].row.resumeVo.educationExperiences[data[0].row.resumeVo.educationExperiences.length -
                                1].schoolName : "无"}</div>
                        </>
                    )
                }
            }
        }
    },
    {
        field: 'sms_typeName',
        label: '所学专业',
        table: {
            slots: {
                default: (data: any) => {
                    return (
                        <>
                            <div>{data[0].row.resumeVo.educationExperiences.length != 0 ? data[0].row.resumeVo.educationExperiences[data[0].row.resumeVo.educationExperiences.length - 1].specialFieldName : "无"}</div>
                        </>
                    )
                }
            }
        }
    },
    {
        field: 'sms_typeName',
        label: '目前职位',
        table: {
            slots: {
                default: (data: any) => {
                    return (
                        <>
                            <div>{data[0].row.resumeVo.personalInformation?.currentPosition || "无"}</div>
                        </>
                    )
                }
            }
        }
    },
    {
        field: 'sms_typeName',
        label: '在职状态',
        table: {
            slots: {
                default: (data: any) => {
                    return (
                        <>
                            <div>{dictFuns(data[0].row.resumeVo.personalInformation?.jobSearchStatus, "status_of_job_hunting") || "无"}</div>
                        </>
                    )
                }
            }
        }
    },
    {
        field: 'sms_typeName',
        label: '到岗时间',
        table: {
            slots: {
                default: (data: any) => {
                    return (
                        <>
                            <div>{dictFuns(data[0].row.resumeVo.personalInformation?.arrivalTime, "arrival_time") || "无"}</div>
                        </>
                    )
                }
            }
        }
    },
    {
        field: 'isRead',
        label: '状态',
        table: {
            slots: {
                default: (data: any) => {
                    return (
                        <>
                            <div>{data[0].row.isRead == 0 ? '未读' : '已读'}</div>
                        </>
                    )
                }
            }
        }
    },

    {
        field: 'sms_typeName',
        label: '政治面貌',
        table: {
            slots: {
                default: (data: any) => {
                    return (
                        <>
                            <div>{dictFuns(data[0].row.resumeVo.personalInformation?.politicalOutlook, "political_outlook") || "无"}</div>
                        </>
                    )
                }
            }
        }
    },
    {
        field: 'sms_typeName',
        label: '简历匹配度',
        table: {
            slots: {
                default: (data: any) => {
                    return (
                        <>
                            <div>{data[0].row.intelligentMatchingDegree * 100 + "%"}</div>
                        </>
                    )
                }
            }
        }
    },
    // 笔试成绩
    {
        field: 'writingTestingStatus',
        label: '笔试通知',
        fixed: "right",
        hidden: true,
        table: {
            slots: {
                default: (data: any) => {
                    return (
                        <>
                            <div>{data[0].row.writingTestingStatus == 0 ? "未通知" : data[0].row.writingTestingResult == 1 ? "已通知" : "已接受"}</div>

                        </>
                    )
                }
            }
        }
    },
    {
        field: 'writingTestingScore',
        label: '笔试成绩',
        fixed: "right",
        hidden: props.type == 2 ? false : true,
    },
    {
        field: 'writingTestingResult',
        label: '笔试结果',
        fixed: "right",
        hidden: props.type == 2 ? false : true,
        table: {
            slots: {
                default: (data: any) => {
                    return (
                        <>
                            <div>{data[0].row.writingTestingResult == 0 ? "未通过" : data[0].row.writingTestingResult == 1 ? "已通过" : "无结果"}</div>
                        </>
                    )
                }
            }
        }

    },
    {
        field: 'writingTestingTime',
        label: '笔试日期',
        fixed: "right",
        hidden: props.type == 2 ? false : true,
    },
    // 面试成绩
    // {
    //     field: 'sms_typeName',
    //     label: '面试轮次',
    //     hidden: true,
    // },
    {
        field: 'interviewDate',
        label: '面试时间',
        fixed: "right",
        hidden: props.type == 3 ? false : true,

    },
    // 体检审查
    {
        field: 'tijian1',
        label: '审查状态',
        hidden: props.type == 4 ? false : true,
        fixed: "right",
        table: {
            slots: {
                default: (data: any) => {
                    return (
                        <>
                            <div>{data[0].row.status}</div>
                        </>
                    )
                }
            }
        }

    },
    {
        field: 'tijian2',
        label: '体检报告上传状态',
        hidden: props.type == 4 ? false : true,
        fixed: "right",
        table: {
            slots: {
                default: (data: any) => {
                    return (
                        <>
                            <div>{data[0].row.medicalReportIds ? "已上传" : "未上传"}</div>
                        </>
                    )
                }
            }
        }
    },
    //入职日期
    {
        field: 'onBoardingTime',
        label: '入职日期',
        fixed: "right",
        hidden: props.type == 5 ? false : true,
    },
    // {
    //     field: 'action',
    //     width: '160px',
    //     label: '操作',
    //     fixed: "right",
    //     search: {
    //         hidden: true
    //     },
    //     form: {
    //         hidden: true
    //     },
    //     detail: {
    //         hidden: true
    //     },
    //     table: {
    //         slots: {
    //             default: (data: any) => {
    //                 return (
    //                     <>
    //                         <ElButton link type="primary" onClick={() => goDetail(data[0].row)}>
    //                             查看详情
    //                         </ElButton>
    //                     </>
    //                 )
    //             }
    //         }
    //     }
    // }
    
    {
        field: 'statusLabel',
        label: '目前流程',
    },
])
const { allSchemas } = useCrudSchemas(crudSchemas)
const handleSizeChange = (val: number) => {//分页
    console.log(`${val} items per page`)
    state.ruleForm.pageSize = val
    positionRegistrationListApi(state.ruleForm)

}
const handleCurrentChange = (val: number) => {//分页大小
    console.log(`current page: ${val}`)
    state.ruleForm.pageNum = val
    positionRegistrationListApi(state.ruleForm)

}
const positionRegistrationListApi = async (params) => {
    let obj = params
    if (typeof obj.currentAddress == "string") {
        obj.currentAddress = params.currentAddress
    } else {
        obj.currentAddress = params.currentAddress ? params.currentAddress.join("") : ""
    }
    // console.log("地址：", obj.currentAddress);
    await positionRegistrationList(params).then((res: any) => {
        console.log("homeData:", res);
        let arrays=res.rows
        arrays.forEach(element => {
            state.statusData.forEach(elements => {
                if(element.status==elements.id){
                    element.statusLabel=elements.label
                }
            });
            
        });
        state.dataList = arrays
        state.total = res.total
    })

}
positionRegistrationListApi(state.ruleForm)
function startWorkTimeFun(res) {
    if (res) {
        let number = 0
        let date = new Date()
        let year = date.getFullYear();
        number = year - res.split("-")[0]
        if (number == 0) {
            return ""
        } else {
            return number + "年工作经验"
        }

    } else {
        return ""
    }
}
</script>

<style lang="less" scoped></style>